package item;

import utiil.ArrayUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Problem24 {


    static int[][] items = new int[][]{
            {9, 4, 7},
            {8, 1, 6},
            {5, 3, 2}
    };

    static int[][] end = new int[][]{
            {1, 2, 3}, {4, 5, 6}, {7, 8, 9}
    };

    static Stack<Integer> stack = new Stack<Integer>();

    public static void main(String[] args) {
        int[][] now = ArrayUtil.copy(items);

    }

    public static void findItem(int[][] now) {
        if (ArrayUtil.isSame(now, end)) {
            ArrayUtil.showArr(stack);
            return;
        }
        if (ArrayUtil.isSame(now, items)) {
            return;
        }
        stack.push(1);
        right(now);
        findItem(now);
        left(now);
        stack.pop();

        stack.push(2);
        up(now);
        findItem(now);
        down(now);
        stack.pop();

        stack.push(3);
        left(now);
        findItem(now);
        right(now);
        stack.pop();
    }

    private static void left(int[][] now) {
        int it = now[0][0];
        for (int a=0;a<3;a++){
            now[0][0]=now[0][1];
            now[0][1]=now[0][2];
            run90(now);
        }
        now[0][0]=it;
        run90(now);
    }

    private static void right(int[][] now){
        int it = now[0][2];
        for (int a=0;a<3;a++){
            now[0][2]=now[0][1];
            now[0][1]=now[0][0];
            run90(now);
        }
        now[0][2]=it;
        run90(now);
    }

    private static void runl90(int[][] now) {
        for (int a = 0; a < now.length; a++) {
            for (int b = 0; b < now[a].length - a; b++) {
                int i = now[b][a];
                now[b][a] = now[a][b];
                now[a][b] = i;
            }
        }

        for (int a=0;a<now.length;a++){
            for (int b=0;b<now[a].length;b++){
                int i = now[now.length-a-1][b];
                now[now.length-a-1][b] = now[a][b];
                now[a][b] = i;
            }
        }
    }
    private static void runR90(int[][] now){
        for (int a = 0; a < now.length; a++) {
            for (int b = 0; b < now[a].length - a; b++) {
                int i = now[b][a];
                now[b][a] = now[a][b];
                now[a][b] = i;
            }
        }

        for (int a=0;a<now.length;a++){
            for (int b=0;b<now[a].length;b++){
                int i = now[now.length-b-1][now[a].length-a-1];
                now[now.length-b-1][now[a].length-a-1] = now[a][b];
                now[a][b] = i;
            }
        }
    }
}
